package com.example.demo1.service;

import com.example.demo1.entity.Girls;
import com.example.demo1.enums.ResultEnum;
import com.example.demo1.exception.GirlException;
import com.example.demo1.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GirlService {
    @Autowired
    private GirlRepository girlRepository;

    @Transactional(rollbackFor = Exception.class)
    public void insertTwo() {
        Girls girlA = new Girls();
        girlA.setId(1);
        girlA.setCupSize("AAAAAA");
        girlA.setAge(22);
        girlRepository.save(girlA);
        Girls girlB = new Girls();
        girlB.setCupSize("F");
        girlB.setAge(50);
        girlRepository.save(girlB);
    }

    public void findeOne(Integer id) throws Exception {
        Girls girls = girlRepository.findOne(id);
        if (girls.getAge() < 10) {
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);

        } else if (girls.getAge() >= 10 && girls.getAge() <= 18) {
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);
        } else {

        }
    }
}
